<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $oreObject escape_repository_OreObject */
	$oreObject =& $this->requestAttributes['oreObject'];
	/* @var $aggregation escape_repository_OreAggregation */
	$aggregation =& $this->requestAttributes['aggregation'];
	/* @var $newRdfType string */
	$newRdfType = $this->requestAttributes['newRdfType'];
	/* @var $incompatibleStatements simplerdf_RdfDocument */
	$incompatibleStatements =& $this->requestAttributes['incompatibleStatements'];
	/* @vat $objectTitles array */
	$objectTitles =& $this->requestAttributes['objectTitles'];
	
	$rdfTypes = $oreObject->getRdfTypes();
	$rdfType = $rdfTypes[0];
	$rdfTypeLabel = $repositoryUi->repository->repositorySchema->getResourceLabel($rdfType);
	
	$newRdfTypeLabel = $repositoryUi->repository->repositorySchema->getResourceLabel($newRdfType);

	$repositoryUi->setTemplateFromAggregation($aggregation);
	
	$templateVariables = array();
	$templateVariables['title'] = 'Change object type';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Section">

<div class="escape_SectionTitle">Change object type</div>

<div class="escape_Selection">
<div class="escape_Object">
<span class="escape_Title"><?php print htmlspecialchars($oreObject->getTitle()); ?></span>
</div>
</div>

<p>
Current object type: <strong><?php print htmlspecialchars($rdfTypeLabel)?></strong>
</p>
<p>
Selected object type: <strong><?php print htmlspecialchars($newRdfTypeLabel)?></strong>
</p>

<?php
	if(count($incompatibleStatements) > 0)
	{
?>
<p>
Unable to change to object type.
The following properties and relations are incompatible with the new type: 
</p>

<?php
		$rdfResources = $incompatibleStatements->getResources();
		foreach($rdfResources as $rdfResource)
		{
?>
<div class="escape_Editor">
<?php
			/* @var $rdfResource simplerdf_RdfResource */
			$subject = $rdfResource->getSubject();
?>

<hr />

<div class="escape_Object">

<div class="escape_Title"><?php print htmlspecialchars($objectTitles[$subject]); ?></div>

<div class="escape_Relation">

<table class="escape_Properties" width="100%" cellpadding="0" cellspacing="0">
	<colgroup>
		<col width="150" />
		<col />
	</colgroup>
<?php
			$predicates = $rdfResource->getPredicates();
			foreach($predicates as $predicate)
			{
?>
	<tr>
		<th>
			<?php print $repositoryUi->repository->repositorySchema->getResourceLabel($predicate); ?>
		</th>
		<td>
<?php
				$objects = $rdfResource->getObjects($predicate);
				foreach($objects as $object)
				{
?>
			<div class="value">
				<?php $repositoryUi->displayPropertyValue($subject, $predicate, $object); ?>
			</div>
<?php
				}
?>
		</td>
	</tr>
<?php
			}
?>
</table>

</div>

</div>

</div>
<?php
		}
?>

<?php
	}
	else
	{
?>
<p>
All properties and relations of this object are compatible with the new type. No properties or relations will be deleted.
</p>
<?php
	}
?>

<form method="post" action="<?php print htmlspecialchars($repositoryUi->getActionLinkById('changeType', $oreObject->getId())); ?>">
<button onclick="escape_escapeUi.redirectToResourceById('edit', <?php print htmlspecialchars(json_encode($oreObject->getId())); ?>); return false">Cancel</button>
</form>

</div>

<?php $this->displayFooter(); ?>
